/**
 * 用infer封装通用性工具-推断
 * 类似于函数的ReturnType<T>
 */

/**
 * type Return<T>工具
 */
type Return<T> = T extends (...args: any[]) => infer R ? R : T;

type sum = (a: number, b: number) => number;
type concat = (a: any[], b: any[]) => any[];

let sumResult: Return<sum>;
let concatResult: Return<concat>;

/**
 * type PromiseType<T>
 */
type PromiseType<T> = T extends Promise<infer K> ? PromiseType<K> : T;

type pt = PromiseType<Promise<Promise<number>>>;

/**
 * type FirstArg<T>
 */
type FirstArg<T> = T extends (first: infer F, ...args: any[]) => any ? F : T;

type fa = FirstArg<(name: string, age: number) => void>;

/**
 * type ArrayType<T>
 */
type ArrayType<T> = T extends (infer I)[] ? I : T;

type ItemType1 = ArrayType<[string, number]>;
type ItemType2 = ArrayType<string[]>;
